package com.xc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xc.exception.BusinessException;
import com.xc.pojo.WhShelf;
import com.xc.result.ResultVO;
import com.xc.service.IWhShelfService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 架子表 前端控制器
 * </p>
 *
 * @author xc
 * @since 2024-05-13
 */
@RestController
@RequestMapping("/wh-shelf")
@Tag(name = "wh货架接口")
@Slf4j
@RequiredArgsConstructor
public class WhShelfController {

    private final IWhShelfService shelfService;

    @GetMapping("/get")
    @Operation(summary = "查询全部")
    public ResultVO<List<WhShelf>> get() {
        log.info("get方法执行了:");
        return ResultVO.success(shelfService.list());
    }

    @GetMapping("/getOne/{id}")
    @Operation(summary = "查询详情")
    public ResultVO<WhShelf> getOne(@PathVariable Long id) {
        return ResultVO.success(shelfService.getById(id));
    }

    @GetMapping("/page")
    @Operation(summary = "测试分页查询货架信息")
    public ResultVO<List<WhShelf>> page(Integer pageNumber, Integer pageSize) {
        return ResultVO.success(shelfService.lambdaQuery().page(Page.of(pageNumber, pageSize)).getRecords());
    }

    @GetMapping("/testEx")
    @Operation(summary = "测试统一异常")
    public ResultVO<Object> testEx(Integer num) {
        log.info("num = {}", num);
        throw new BusinessException(9999, num + "货架不存在");
    }
}
